home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / Allgame.ifs < prev    next >
Text File  |  2005-02-11  |  16KB  |  392 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=scorpion7552
  8. Title=AllGame
  9. Description=import games - Default platform & Normal/Batch mode: see Comments tab 
  10. Site=www.allgame.com
  11. Language=EN
  12. Version=2.0
  13. Requires=3.5.0
  14. Comments=default platform: after selecting option 1 or 2 for platform, don't forget to select option 0 the next time you run this script||Batch mode: you must have a database already created with this script (I use the url stored)|Don't forget to save your database before executing the batch mode and select a reasonable number of games at a time|At the end of each round, look at file C:\amc_AllGame_batchlog.txt for informations and  errors (this file is re-create each time you run this script)
  15. License=This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
  16. GetInfo=1
  17.  
  18. [Options]
  19. Platform=0|0|0=use current setting|1=choose default platform|2=reset default platform
  20. Mode=0|0|0=normal mode|1=batch mode (url)
  21.  
  22. ***************************************************)
  23.  
  24. // needs the following units
  25. // StringUtils1.pas, StringUtils7552.pas
  26.  
  27. program AllGame;
  28. uses
  29.     StringUtils7552;
  30.     
  31. const
  32.     AllGameUrl = 'http://www.allgame.com';       // base url
  33.     batchlogfic = 'c:\amc_AllGame_batchlog.txt'; // log for batch mode
  34.     platformopt = 'Platform';                    // name of platform Static option
  35. // debug mode
  36.     debug = False;                               // debug mode on/off
  37.     debugrep = 'd:\temp\';                       // directory where to save files
  38.  
  39. var
  40.     GameName, platformc, firstcall, abort, msgano: String;
  41.     BatchMode, dfltPlatform: Integer;
  42.     batchlog, confbatch, memo: TstringList;
  43.     gameok: boolean;
  44.     
  45. //------------------------------------------------------------------------------
  46. // get platform id (normal mode only)
  47. // on output, platformc = name of selected platform 
  48. //------------------------------------------------------------------------------
  49. procedure GetPlatform;   
  50. var
  51.     Page, Line, Table, urlplatform: string; 
  52.     i: integer;
  53.  
  54. begin
  55.     msgano := 'Enter platform name';
  56.     if dfltPlatform = 1 then                            // change default platform
  57.     begin
  58.         platformc := GetStatic(platformopt);                // get old default or ''
  59.         msgano := 'Select a (new) default platform';
  60.     end;
  61.     repeat
  62. // enter platform name; leave script if nothing entered
  63.     if not Input('AllGame.com Import', msgano, platformc) or (platformc = '') then exit;
  64. // look if there is something matching platformc
  65.     Page := PostPage(AllGameUrl+'/cg/agg.dll', 'SRCH='+platformc+'&P=agg&TYPE=5');
  66.     if debug then
  67.         DumpPage(debugrep+'SelPlatformAllGame.txt', Page);    // debug
  68.     if Pos('Game Platforms Matching', Page) = 0 then
  69.     begin
  70.         ShowError('Error while reading platform page');  
  71.         exit;                         // leave script if big error
  72.     end;
  73. // selection table
  74.     Table := TextBetween(Page, '<TABLE BORDER=0 WIDTH=300 CELLPADDING=1 CELLSPACING=1>', '</TABLE>');
  75.     if Table = '' then
  76.     begin
  77.         msgano := 'No platform found for "'+platformc+'"';                // iterate
  78.         platformc := '';
  79.     end else
  80.     begin
  81. // extract matching platform names (displayed on a single page)
  82.         memo := TStringList.Create;
  83.         memo.Text := StringReplace(Table, '</TR>', crlf);  // separate lines (keep other crlf)
  84.         PickTreeClear;                                     // clear list
  85.         PickTreeAdd('Select platform', '');
  86.         urlplatform := 'HREF=/cg/agg.dll';                 // url to search 
  87.         for i := 0 to memo.Count -1 do                     // list of games   
  88.         begin                                            
  89.             Line := memo.GetString(i);                       // extract current line
  90.             if GetUrl(Line, urlplatform, AllGameUrl) = '' then continue;    // no url: header or empty line
  91.             Line := TextBefore(Line, '</A>', '>');           // platform name 
  92.             PickTreeAdd(Line, Line);
  93.         end;         {for i}                
  94.         memo.Free;
  95.         if not PickTreeExec(platformc) then
  96.             msgano := 'No platform selected';       // iterate if no platform selected
  97.     end;
  98.     until (platformc <> '');
  99.     if dfltPlatform = 1 then
  100.     begin
  101.         SetStatic(platformopt, platformc);              // save new default platform
  102.         ShowInformation('Default platform "'+platformc+'" have been saved'+crlf+'Next time, don''t forget to set the option back to 0');
  103.     end;
  104. end;
  105.  
  106. //------------------------------------------------------------------------------
  107. // list of games running on platformc 
  108. // GameName = name of game
  109. //------------------------------------------------------------------------------
  110. procedure GetList;   
  111. var
  112.     Address, Table, Line, Value, Page, urlgame, name, genre: String;
  113.     found: boolean;
  114.     i: integer;
  115.  
  116. begin
  117.     PickTreeClear;                                     // clear list
  118.     found := False;
  119.     PickTreeAdd('List of games (platform='+platformc+')', '');
  120.     Page := PostPage(AllGameUrl+'/cg/agg.dll', 'SRCH='+UrlEncode(GameName)+'&P=agg&TYPE=1');
  121.     if debug then
  122.         DumpPage(debugrep+'choiceAllGame.txt', Page);    // debug
  123.     if Pos('Games with Titles Matching', Page) = 0 then
  124.     begin
  125.         LogMessage('Error while reading selection page');
  126.         exit;
  127.     end;
  128.     if Pos('No matches found', Page) > 0 then
  129.     begin
  130.         LogMessage('No matches found for "'+GameName+'"');
  131.         exit;
  132.     end;
  133. // selection table
  134. // note: the games are displayed on one page and are sorted by relevance
  135.     Table := TextBetween(Page, '<TABLE BORDER=0 WIDTH=610 CELLPADDING=1 CELLSPACING=1>', '</TABLE>');
  136. // strange coding
  137. // normally, a table has the following structure
  138. // <TR ...>                      = start of line
  139. //   <TD ...> text </TD>         = one cell
  140. //   ................            = other cells
  141. // </TR>                         = end of line
  142. // but, I don't know why they omit the </TR> in this table
  143. // so, I have to separate lines with '<TR'
  144.     Table := StringReplace(Table, crlf, '');             // must remove crlf
  145.     memo := TStringList.Create;
  146.     memo.Text := StringReplace(Table, '<TR', '<'+crlf);  // separate lines
  147.     urlgame := 'HREF=/cg/agg.dll';                 // url to search (first occurence)
  148.     for i := 0 to memo.Count-1 do                  // list of games
  149.     begin 
  150.         Line := memo.GetString(i);                     // extract current line
  151.         Address := GetUrl(Line, urlgame, AllGameUrl);  // get url of game page
  152.         if Address = '' then continue;                 // no url: header or empty line
  153.         Line := TextAfter(Line, urlgame);                  // keep infos after url
  154.         Line := TextAfter(Line, '>');                      // usefull infos
  155.         Line := StringReplace(Line, '</TD>', sepchar1);    // separate fields with </TD>
  156.         Line := FormatText(Line);                          // remove extra tags
  157.         name := Trim(TextBefore(Line, sepchar1, ''));      // name of the game
  158.         Line := RemainingText;
  159.         genre := Trim(TextBefore(Line, sepchar1, ''));     // genre
  160.         Line := RemainingText;                                
  161.         Line := TextBefore(Line, sepchar1, ''); 
  162.         Line := RemainingText;                             // skip style 
  163.         Value := Trim(TextBefore(Line, sepchar1, ''));     // Platform 
  164. // 'IBM PC Compatible' = PC, PC DOS Win95, etc...
  165.         if Left(Value, 2) = 'PC' then Value := 'IBM PC Compatible';             
  166.         if Value = platformc then          // current game runs on selected platform
  167.         begin
  168.             PickTreeAdd(name+' ('+genre+')', Address);
  169.             found := True;
  170.         end;
  171.     end;         {for i}
  172.     memo.Free;
  173.     if not found then
  174.     begin
  175.         LogMessage('No game found for "'+GameName+'" running on "'+platformc+'"');
  176.         exit;
  177.     end;
  178.     PickTreeSort;                                  // sort the list 
  179.     if PickTreeExec(Address) then
  180.         AnalyzeGamePage(Address)                     // game page
  181.     else
  182.         LogMessage('No game selected');
  183. end;
  184.  
  185. //------------------------------------------------------------------------------
  186. // ANALYZE GAME PAGE
  187. //------------------------------------------------------------------------------
  188. procedure AnalyzeGamePage(Address: string);
  189.  
  190. var
  191.     Page, Line, Table, Value, Value2, screenshot, cover: String;
  192.     i: Integer;
  193.  
  194. begin
  195.     Page := GetPage(Address);         
  196.     if debug then
  197.         DumpPage(debugrep+'gameAllGame.txt', Page);    // debug
  198.     if Pos('Release', Page) = 0 then
  199.     Begin 
  200.         LogMessage('Error while reading game page');
  201.         exit;
  202.     end;
  203.     SetField(fieldURL, Address);
  204.     gameok := True;
  205. //*** title (original only)
  206.     Table := TextBetween(Page, '<TABLE BORDER=0 BGCOLOR=#D8D8D8 WIDTH=610 CELLPADDING=5 CELLSPACING=0>', '</TABLE>');
  207.     Table := FormatText(Table);
  208.     if Table <> '' then
  209.         SetField(fieldOriginalTitle, Table);
  210. // rating  (<IMG SRC="/im/agg/st_ptX.jpg"  with X = rating)
  211.     Value := TextBetween(Page, '<IMG SRC="/im/agg/st_pt', '.jpg"');  
  212.     SetField(fieldRating, Value);
  213. //*** platform (= country), genre (= category) and style (no field for that)
  214.     Table := TextBetween(Page, '<TABLE BORDER=0 BORDERCOLOR="WHITE" WIDTH="126" CELLSPACING=2 CELLPADDING=0>', '</TABLE>');
  215.     Table := StringReplace(Table, crlf, '');             // must remove crlf
  216.     memo := TStringList.Create;
  217.     memo.Text := StringReplace(Table, '</TR>', crlf);    // separate lines    
  218.     if memo.Text <> '' then
  219.     begin
  220.         Value := memo.GetString(0);                        // platform 
  221.         SetField(fieldCountry, FormatText(Value));
  222.         Value := memo.GetString(1);                        // genre
  223.         SetField(fieldCategory, FormatText(Value));
  224.     end;
  225.     memo.Free;
  226. // get 1st screenshot if any
  227.     Table := TextBetween(Page, '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>', '</TABLE>');
  228.     if Table <> '' then
  229.         screenshot := GetUrl(Table, '', '');
  230. //*** release date (year only)  ('month year' 'month day, year' or 'year')
  231.     Table := TextAfter(Page, '<TABLE WIDTH=610 BORDER=0 CELLPADDING=1 CELLSPACING=1>');  // more than one table
  232.     Value := FormatText(TextBetween(Table,'Release', '</TR>'));
  233.     i := LastPos(' ', Value);                      // extract year only
  234.     if i > 0 then Value := Copy(Value, i+1, length(Value)); 
  235.     SetField(fieldYear, Value);
  236. // developper (= director)
  237.     Value := TextBetween(Table,'Developer', '</TR>');
  238.     SetField(fieldDirector, FormatText(Value));
  239. // publisher (= producer)
  240.     Value := TextBetween(Table,'Publisher', '</TR>');
  241.     SetField(fieldProducer, FormatText(Value));
  242. // various infos (= comments) controls, hardware supported, etc...
  243.     Value2 := '';
  244.     Value2 := Value2+ExtrInfo(Table,'Controls');
  245.     Value2 := Value2+ExtrInfo(Table,'Warnings');
  246.     Value2 := Value2+ExtrInfo(Table,'Flags');
  247.     Value2 := Value2+ExtrInfo(Table,'Hardware Supported');
  248.     Value2 := Value2+ExtrInfo(Table,'Supports');
  249.     Value2 := Value2+ExtrInfo(Table,'Included in Package');
  250.     Value2 := Value2+ExtrInfo(Table,'Similar Games');
  251.     SetField(fieldComments, FormatText(Value2));
  252. //*** description and image
  253.     Line := '<TABLE border=0 BGCOLOR="#D8D8D8" CELLSPACING=10 CELLPADDING=10 WIDTH="600">';
  254.     Value := TextBetween(Page, Line, '</TABLE>');            // 1st (or only) description 
  255.     Table := RemainingText;                                  // is there another description ?
  256.     if Value <> '' then
  257.     begin
  258.         cover := TextBetween(Value, '<IMG SRC="', '"');        // cover url 
  259.         Value := FormatText(Value);                            // 1st description
  260.         Value2 := FormatText(TextBetween(Table, Line, '</TABLE>'));
  261.         if Value2 <> '' then                                   // another description
  262.             Value := Value+crlf+Value2;
  263.     end;
  264.     SetField(fieldDescription, Value);
  265.     if cover = '' then cover := screenshot; // no cover: get 1st screenshot if any
  266.     if (cover <> '') and CanSetPicture then
  267.         GetPicture(cover);
  268. end;
  269.  
  270. //------------------------------------------------------------------------------
  271. // extract 'various infos'
  272. //------------------------------------------------------------------------------
  273. function ExtrInfo(str1, str2: string) :string;
  274.  
  275. begin
  276.     str1 := FormatText(TextBetween(str1, str2, '</TR>'));
  277.     if str1 <> '' then str1 := crlf+str2+': '+str1;
  278.     result := str1;
  279. end;
  280.  
  281. //------------------------------------------------------------------------------
  282. // set msgano (normal mode) or add to log (batch mode) 
  283. //------------------------------------------------------------------------------
  284. procedure LogMessage(m: string);
  285. begin
  286.     if BatchMode > 0 then 
  287.         AddToLog('item '+GetField(fieldNumber)+': '+m)
  288.     else
  289.         msgano := m;
  290. end;
  291.  
  292. //------------------------------------------------------------------------------
  293. // add a message in the batch log and save to disk
  294. // (because I don't know when it's finished...)
  295. //------------------------------------------------------------------------------
  296. procedure AddToLog(m: string);
  297. begin
  298.     batchlog.Add(m);
  299.     batchlog.SaveToFile(batchlogfic);
  300. end;
  301.  
  302. //------------------------------------------------------------------------------
  303. // process batch mode
  304. //------------------------------------------------------------------------------
  305. procedure AllGameBatch;
  306. begin
  307.     GameName := GetField(fieldUrl);       // if no url or another site then ignore
  308.     if (GameName <> '') and (Pos(AllGameUrl, GameName) > 0) then
  309.         AnalyzeGamePage(GameName)
  310.     else
  311.         LogMessage('ignored url="'+GameName+'"');
  312. end;    
  313.     
  314. //------------------------------------------------------------------------------
  315. // process normal mode
  316. //------------------------------------------------------------------------------
  317. procedure AllGameNorm;
  318. begin
  319.     platformc := '';                          
  320.     case dfltPlatform of
  321.     0: platformc := GetStatic(platformopt);   // current = default platform or ''
  322.     1: platformc := '';                       // choose (new) default
  323.     2:                                        // reset default platform
  324.         begin
  325.             platformc := '';                       
  326.             SetStatic(platformopt, ' ');
  327.         end;
  328.     end; 
  329.     gameok := False;
  330.     if platformc = '' then   
  331.         GetPlatform;                               // if no default, select platform
  332.     if platformc <> '' then
  333.     begin
  334.         GameName := GetField(fieldOriginalTitle);     // then game name
  335.         msgano := 'Enter game name for platform "'+platformc+'"';
  336.         repeat
  337.         if not Input('AllGame.com Import', msgano, GameName) or (GameName = '') then exit;
  338.         GetList;
  339.         until gameok;
  340.     end;
  341. end;
  342.     
  343. //------------------------------------------------------------------------------
  344. //  start here
  345. //------------------------------------------------------------------------------                                               
  346. begin
  347.     if abort = 'o' then exit;                                // batch mode aborted
  348.     if firstcall <> 'done' then
  349.     begin                                             // 1st call: init parameters
  350.         firstcall := 'done';
  351.         if not CheckVersion(3,5,0) then
  352.         begin
  353.             ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');        
  354.             abort := 'o';
  355.             exit;
  356.         end;    
  357. // get user's parms (used more than once)
  358.         dfltPlatform := GetOption(platformopt);
  359.         BatchMode := GetOption('Mode');
  360. //
  361.         if BatchMode > 0 then                      // batch mode: confirm the choice
  362.         begin
  363.             batchlog := TStringList.Create;            // init batch log
  364.             batchlog.Add('starting batch mode');   
  365.             batchlog.Add(StringOfChar('*',80));
  366.             batchlog.SaveToFile(batchlogfic);
  367. // confirmation message
  368.             confbatch := TStringList.Create;
  369.             confbatch.Add('You have selected the batch mode:');
  370.             confbatch.Add('Have you saved your database?');
  371.             confbatch.Add('');
  372.           confbatch.Add('At the end of treatement:'); 
  373.             confbatch.Add('- look at the file '+batchlogfic+' for errors/infos');
  374.           confbatch.Add('- the games found will be checked, the others not (for the selection)');
  375.              confbatch.Add(' (see: Tools/Preferences/Movie list/checkboxes)');
  376.             confbatch.Add('');
  377.             confbatch.Add('confirm your choice');    
  378.             if not ShowWarning(confbatch.Text) then
  379.             begin
  380.               AddToLog('batch mode aborted');    // batch mode not confirmed = abort
  381.                 abort := 'o';
  382.                 exit;
  383.             end;
  384.         end;
  385.     end;
  386. // let's go
  387.     if BatchMode = 0 then
  388.         AllGameNorm
  389.     else
  390.         AllGameBatch; 
  391. end.
  392.